package com.guoyw.leetcode.question.everyday.Y2021.M03;

/**
 * @Description: 82. 删除排序链表中的重复元素 II
 * @Author: guoyw
 * @CreateDate: 2021/3/25 4:18 下午
 * @Version: 1.0
 */

public class Day25_C82 {

  // to 82. 删除排序链表中的重复元素 II
  public ListNode deleteDuplicates(ListNode head) {
    if (head == null) {
        return head;
    }

    ListNode satr = new ListNode(0,head);
    ListNode cur = satr;
    while (cur.next != null && cur.next.next != null) {
        if(cur.next.val == cur.next.next.val ){
          int x = cur.next.val;
          while (cur.next != null && cur.next.val == x) {
            cur.next = cur.next.next;
          }
        }else {
          cur = cur.next;
        }
    }
    return satr.next;
  }

  public class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }
}
